package com.sk.bilibili.interceptor;

/**
 * @author 邵康
 * @date 2021/12/18 15:07
 */

import com.sk.bilibili.handler.numHandler.BeforeUpdateHandler;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
})//用于处理更新删除  缓存  因为 一更新就是全量更新
public class BeforeUpdateInterceptor extends BaseInterceptor<BeforeUpdateHandler> {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object[] args = invocation.getArgs();
        handleValue(args[1]);
        return invocation.proceed();
    }

    @Override
    protected void handleValue(BeforeUpdateHandler handler, Object res) {
        handler.beforeHandle(res);
    }

}
